import { useNotice } from '@/components/element-plus/notice';
import { Options, ResponseCodeEnum, useHttpClient } from 'pf-component';
import { camundaApi } from '@/constants/api/camunda-api';
export const useOrg = () => {
  const { message } = useNotice();
  // @ts-ignore
  const effectUserList = ({ pageNum, pageSize }): Promise<any> => {
    return useHttpClient()
      .general<any>(camundaApi.processOrgApi.effectUserList, { pageNum, pageSize })
      .then(res => {
        if (res.code === ResponseCodeEnum.SUCCESS) {
          if (res.data?.records) {
            res.data.records = res.data.records.map((r: any) => {
              r.userBirthday =
                r.userBirthday?.length > 10 ? r.userBirthday.substring(0, 10) : r.userBirthday;
              return r;
            });
          }
          return res.data;
        } else {
          message.error(res.message);
          return { total: 0, records: [] };
        }
      });
  };
  // @ts-ignore
  const effectDeptList = ({ pageNum, pageSize }): Promise<any> => {
    return useHttpClient()
      .general<any>(camundaApi.processOrgApi.effectDeptList, { pageNum, pageSize })
      .then(res => {
        if (res.code === ResponseCodeEnum.SUCCESS) {
          return res.data;
        } else {
          message.error(res.message);
          return { total: 0, records: [] };
        }
      });
  };
  return { effectUserList, effectDeptList };
};
